﻿<%@ Page Language="c#" ContentType="text/html" ResponseEncoding="utf-8" Async="true" MasterPageFile="~/administration/master_popup.master" Inherits="ACM.cmsarea08.Administration.Core.OptPageBase" %>
<%@ MasterType VirtualPath="~/administration/master_popup.master" %>



<asp:Content ID="PageBody" Runat="server" ContentPlaceHolderID="MasterBody">
<div id="option_popup">
<div class="popup_msgs">

</div>
<div class="popup_input" style="height:150px;">
<asp:FileUpload ID="fileupload" runat="server"></asp:FileUpload>
<asp:LinkButton ID="upload" Text="Upload!" runat="server" OnClick="Upload"></asp:LinkButton>
</div>
<input type="hidden" id="newvalue" runat="server"  />

</div>

<script language="c#" runat="server">

protected override void OnInit(EventArgs e){
	base.OnInit(e);

//Response.Write(string.Format(query,ACM.cmsarea08.mainconfiguration.MainConf.PrefissoTabelle,Request.QueryString["findid"].ToString()));

}
private void Page_Load(Object o, EventArgs e){
if(HttpUtility.HtmlDecode(Request.QueryString["folder"])==null){
	Response.Write("Errore server");
	return;
}
string cartella = HttpUtility.HtmlDecode(Request.QueryString["folder"].ToString());

	
}
private void Upload(Object o, EventArgs e){
if(fileupload.FileName.Trim()==""){
	Response.Write("nessun file selezionato");
	return;	
}

string cartella = HttpUtility.HtmlDecode(Request.QueryString["folder"].ToString());
	if(cartella.Trim()=="")
		this.Controls.Add(new LiteralControl("vuoi salvare " + fileupload.FileName + " nella root"));
	else
				this.Controls.Add(new LiteralControl("vuoi salvare " + fileupload.FileName + " in " + cartella));
SalvaFile(cartella);
}

private void SalvaFile(string cartella){
System.IO.FileInfo fi = new System.IO.FileInfo(Server.MapPath("/public/media/" + cartella + fileupload.FileName));
 	if(fi.Exists){
		System.IO.FileInfo finew = new System.IO.FileInfo(Server.MapPath("/public/media/" + cartella) + rm.GetString("copy_of")+" "+fi.Name);
		int count = 1;
		while(finew.Exists){
			finew = new System.IO.FileInfo(Server.MapPath("/public/media/" + cartella) + rm.GetString("copy_of")+" "+fi.Name.Substring(0,fi.Name.Length-fi.Extension.Length)+"("+ count.ToString() +")" + fi.Extension);
			count++;
		}
//		fi.CopyTo(finew.FullName,true);
		fileupload.SaveAs(finew.FullName);			
		Response.Write("<br>"+finew.FullName+" Fatto!<br>");
	}
	else{
		fileupload.SaveAs(Server.MapPath("/public/media/" + cartella) + fileupload.FileName);			
		Response.Write("<br>"+Server.MapPath("/public/media/" + cartella) + fileupload.FileName+" Fatto!<br>");
	}
	
}
</script>




</asp:content>